<?
class FunctionLib{
	static $check_uri = false;

	/*-------------------------------------------------------------------------*/
	// Sets a cookie, abstract layer allows us to do some checking, etc
	/*-------------------------------------------------------------------------*/
	static function my_setcookie($name="", $value = "", $expires=""){
		$name = COOKIE_ID."_".$name;
		$expires = ($expires)? $expires : time() + 60*60*24*365;
		$cookie_path = '/';
		$cookie_domain = "";
		if(preg_match("/muachung.vn/", $_SERVER['HTTP_HOST'])){
			$cookie_domain = '.muachung.vn';
		}
		setcookie($name, $value, $expires, $cookie_path, $cookie_domain);
		//setcookie($name, $value, $expires, $cookie_path);
		$_COOKIE[$name] = $value;
	}

	static function get_cookie($name="", $def = ""){
		$name = COOKIE_ID."_".$name;
		return isset($_COOKIE[$name]) ? $_COOKIE[$name] : $def;
	}
	
	static function isCookieExisted($name=""){
		return isset($_COOKIE[COOKIE_ID."_".$name]);
	}

	static function strippedLink($str,$length=68){
		if ( (strlen($str) - $length ) < 3 ){
			return $str;
		}
		return substr( $str , 0, floor(($length-3)/2) ).'...'.substr( $str , -floor(($length-3)/2) );
	}

	// ham tao descprtion trong tag DESCRIPTION
	static function descriptionText($str){
		
		$meta_desc = FunctionLib::post_db_parse_html($str);
		
		$meta_desc = FunctionLib::plainText($meta_desc);
		$meta_desc = html_entity_decode($meta_desc,ENT_QUOTES,"UTF-8");
		$meta_desc = str_replace('\'','',$meta_desc);
		$meta_desc = str_replace('"','',$meta_desc);
		return $meta_desc;
	}

	static function plainText($str){
		$str = strip_tags($str);
		$str = self::trimSpace(str_replace(array(chr(13),chr(9),chr(10),chr(239))," ",$str));
		return self::delDoubleSpace($str);
	}


	static function base64_url_encode($input) {
		return str_replace('=','',strtr(base64_encode($input), '+/', '-_'));
	}

	static function _name_cleaner($name,$replace_string="_"){
		return preg_replace( "/[^a-zA-Z0-9\-\_]/", $replace_string , $name );
	}

	static function make_safe_name($name,$replace_string="_"){
		return preg_replace( "/[^\w\.]/", $replace_string , $name );
	}

	static function convertUnicodeCase($test){
		$uppercase_utf8=array("A","Á","À","Ả","Ã","Ạ","Â","Ấ","Ầ","Ẩ","Ẫ","Ậ","Ă","Ắ","Ằ","Ẳ","Ẵ","Ặ","E","É","È","Ẻ","Ẽ","Ẹ","Ê","Ế","Ề","Ể","Ễ","Ệ","I","Í","Ì","Ỉ","Ĩ","Ị","O","Ó","Ò","Ỏ","Õ","Ọ","Ô","Ố","Ồ","Ổ","Ỗ","Ộ","Ơ","Ớ","Ờ","Ở","Ỡ","Ợ","U","Ú","Ù","Ủ","Ũ","Ụ","Ư","Ứ","Ừ","Ử","Ữ","Ự","Y","Ý","Ỳ","Ỷ","Ỹ","Ỵ","Đ"," ", "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "_", "+", "=", "|", "\\", "{", "}",":", ";", "<", ">", "/", "?");
		$lowercase_utf8=array("a","á","à","ả","ã","ạ","â","ấ","ầ","ẩ","ẫ","ậ","ă","ắ","ằ","ẳ","ẵ","ặ","e","é","è","ẻ","ẽ","ẹ","ê","ế","ề","ể","ễ","ệ","i","í","ì","ỉ","ĩ","ị","o","ó","ò","ỏ","õ","ọ","ô","ố","ồ","ổ","ỗ","ộ","ơ","ớ","ờ","ở","ỡ","ợ","u","ú","ù","ủ","ũ","ụ","ư","ứ","ừ","ử","ữ","ự","y","ý","ỳ","ỷ","ỹ","ỵ","đ","", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "","", "", "", "", "", "", "", "", "");
		if(!$test){
			return $test;
		} else {
			$new_test=str_replace($uppercase_utf8,$lowercase_utf8,$test);
			return $new_test;
		}
	}
	
	static function convertUnicodeCaseWithoutHtml($test){
		$uppercase_utf8=array("A","Á","À","Ả","Ã","Ạ","Â","Ấ","Ầ","Ẩ","Ẫ","Ậ","Ă","Ắ","Ằ","Ẳ","Ẵ","Ặ","E","É","È","Ẻ","Ẽ","Ẹ","Ê","Ế","Ề","Ể","Ễ","Ệ","I","Í","Ì","Ỉ","Ĩ","Ị","O","Ó","Ò","Ỏ","Õ","Ọ","Ô","Ố","Ồ","Ổ","Ỗ","Ộ","Ơ","Ớ","Ờ","Ở","Ỡ","Ợ","U","Ú","Ù","Ủ","Ũ","Ụ","Ư","Ứ","Ừ","Ử","Ữ","Ự","Y","Ý","Ỳ","Ỷ","Ỹ","Ỵ","Đ","Q","W","R","T","U","S","D","F","G","H","J","K","L","Z","X","C","V","B","N","M","P");
		$lowercase_utf8=array("a","á","à","ả","ã","ạ","â","ấ","ầ","ẩ","ẫ","ậ","ă","ắ","ằ","ẳ","ẵ","ặ","e","é","è","ẻ","ẽ","ẹ","ê","ế","ề","ể","ễ","ệ","i","í","ì","ỉ","ĩ","ị","o","ó","ò","ỏ","õ","ọ","ô","ố","ồ","ổ","ỗ","ộ","ơ","ớ","ờ","ở","ỡ","ợ","u","ú","ù","ủ","ũ","ụ","ư","ứ","ừ","ử","ữ","ự","y","ý","ỳ","ỷ","ỹ","ỵ","đ","q","w","r","t","p","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m","p");
		if(!$test){
			return $test;
		} else {
			$new_test=str_replace($uppercase_utf8,$lowercase_utf8,$test);
			return $new_test;
		}
	}

	static function safe_title($text){
		$text = FunctionLib::post_db_parse_html($text);
		$text = self::stripUnicode($text);
		$text = self::_name_cleaner($text,"-");
		$text = str_replace("----","-",$text);
		$text = str_replace("---","-",$text);
		$text = str_replace("--","-",$text);
		$text = trim($text, '-');

		if($text){
			return $text;
		}
		else{
			return "shop";
		}
	}

	static function convert_one_br($text){
		$text = str_replace("<br /><br /><br /><br /><br />","<br />",$text);
		$text = str_replace("<br /><br /><br /><br />","<br />",$text);
		$text = str_replace("<br /><br /><br />","<br />",$text);
		$text = str_replace("<br /><br />","<br />",$text);

		return trim($text, '<br />');
	}

	static function stripUnicode($str){
		if(!$str) return false;
		$marTViet=array("à","á","ạ","ả","ã","â","ầ","ấ","ậ","ẩ","ẫ","ă",
		"ằ","ắ","ặ","ẳ","ẵ","è","é","ẹ","ẻ","ẽ","ê","ề"
		,"ế","ệ","ể","ễ",
		"ì","í","ị","ỉ","ĩ",
		"ò","ó","ọ","ỏ","õ","ô","ồ","ố","ộ","ổ","ỗ","ơ"
		,"ờ","ớ","ợ","ở","ỡ",
		"ù","ú","ụ","ủ","ũ","ư","ừ","ứ","ự","ử","ữ",
		"ỳ","ý","ỵ","ỷ","ỹ",
		"đ",
		"À","Á","Ạ","Ả","Ã","Â","Ầ","Ấ","Ậ","Ẩ","Ẫ","Ă"
		,"Ằ","Ắ","Ặ","Ẳ","Ẵ",
		"È","É","Ẹ","Ẻ","Ẽ","Ê","Ề","Ế","Ệ","Ể","Ễ",
		"Ì","Í","Ị","Ỉ","Ĩ",
		"Ò","Ó","Ọ","Ỏ","Õ","Ô","Ồ","Ố","Ộ","Ổ","Ỗ","Ơ"
		,"Ờ","Ớ","Ợ","Ở","Ỡ",
		"Ù","Ú","Ụ","Ủ","Ũ","Ư","Ừ","Ứ","Ự","Ử","Ữ",
		"Ỳ","Ý","Ỵ","Ỷ","Ỹ",
		"Đ");

		$marKoDau=array("a","a","a","a","a","a","a","a","a","a","a"
		,"a","a","a","a","a","a",
		"e","e","e","e","e","e","e","e","e","e","e",
		"i","i","i","i","i",
		"o","o","o","o","o","o","o","o","o","o","o","o"
		,"o","o","o","o","o",
		"u","u","u","u","u","u","u","u","u","u","u",
		"y","y","y","y","y",
		"d",
		"A","A","A","A","A","A","A","A","A","A","A","A"
		,"A","A","A","A","A",
		"E","E","E","E","E","E","E","E","E","E","E",
		"I","I","I","I","I",
		"O","O","O","O","O","O","O","O","O","O","O","O"
		,"O","O","O","O","O",
		"U","U","U","U","U","U","U","U","U","U","U",
		"Y","Y","Y","Y","Y",
		"D");

		$str = str_replace($marTViet,$marKoDau,$str);
		return $str;
	}

	static function getExtension($file) {
		$tail = strtolower(strrchr($file,"."));
		return substr($tail, 1);
	}

	static function getParam($aVarName,$aVarAlt=""){ // chi lay post va get
		$lVarName = isset($_GET[$aVarName]) ? $_GET[$aVarName] : (isset($_POST[$aVarName]) ? $_POST[$aVarName] : $aVarAlt);
		if($lVarName != $aVarAlt){
			if(is_array($lVarName)){
				$lReturnArray = array();
				foreach ($lVarName as $key => $value) {
					$value = self::clean_value($value);
					$key = self::clean_key($key);
					$lReturnArray[$key] = $value;
				}
				return $lReturnArray;
			}else{
				return self::clean_value($lVarName); // Clean input and return it
			}
		}
		return $lVarName;
	}

	static function cleanHtml($aVarName,$aVarAlt=""){
		$lVarName = $aVarName;
		if (!empty($lVarName)){
			if (is_array($lVarName)){
				$lReturnArray = array();
				foreach ($lVarName as $key => $value) {
					$value = self::clean_value($value);
					$key = self::clean_key($key);
					$lReturnArray[$key]=$value;
				}
				return $lReturnArray;
			}
			return self::clean_value($lVarName); // Clean input and return it
		}
		return $aVarAlt;
	}

	static function getParamInt($aVarName,$aVarAlt=0){
		$lNum = 0;
		if ($aVarName){
			if (isset($_POST[$aVarName])){
				$lNum = $_POST[$aVarName];
			}
			elseif (isset($_GET[$aVarName])){
				$lNum = $_GET[$aVarName];
			}
			else{
				$lNum = $aVarAlt;
			}
		}
		return (int)$lNum;
	}

	/*-------------------------------------------------------------------------*/
	// Key Cleaner - ensures no funny business with form elements
	/*-------------------------------------------------------------------------*/
	static function clean_key($key){
		if ($key == ""){
			return "";
		}

		$key = htmlspecialchars(urldecode($key));
		$key = preg_replace( "/\.\./"           , ""  , $key );
		$key = preg_replace( "/\_\_(.+?)\_\_/"  , ""  , $key );
		$key = preg_replace( "/^([\w\.\-\_]+)$/", "$1", $key );
		return $key;
	}

	/*-------------------------------------------------------------------------*/
	// Clean value
	/*-------------------------------------------------------------------------*/

	static function clean_value($val){
		$strip_space_chr = 1;
		$get_magic_quotes = @get_magic_quotes_gpc();

		if ($val == ""){
			return "";
		}

		//halm: them trim vao 22-3-2011
		$val = trim($val);
		$val = str_replace( "&#032;", " ", $val );

		if ( $strip_space_chr ){
			$val = str_replace( chr(0xCA), "", $val );  //Remove sneaky spaces
		}
		//$val = str_replace( "&"            , "&amp;"         , $val );
		$val = str_replace( "<!--"         , ""  , $val ); //&#60;&#33;--
		$val = str_replace( "-->"          , ""       , $val ); //--&#62;
		$val = preg_replace( "/<script/i"  , "&#60;script"   , $val );
		$val = str_replace( ">"            , "&gt;"          , $val );
		$val = str_replace( "<"            , "&lt;"          , $val );
		$val = str_replace( "\""           , "&quot;"        , $val );
		//$val = preg_replace( "/\n/"        , "<br />"        , $val ); // Convert literal newlines
		$val = preg_replace( "/\\\$/"      , "&#036;"        , $val );
		$val = preg_replace( "/\r/"        , ""              , $val ); // Remove literal carriage returns
		$val = str_replace( "!"            , "&#33;"         , $val );
		$val = str_replace( "'"            , "&#39;"         , $val ); // IMPORTANT: It helps to increase sql query safety.

		if ( $get_magic_quotes ){
			$val = stripslashes($val);
		}

		$val = preg_replace( "/\\\(?!&amp;#|\?#)/", "&#092;", $val );

		return $val;
	}

	//-----------------------------------------
	// parse_html
	// Converts the doHTML tag
	//-----------------------------------------
	static function post_db_parse_html($t=""){
		if ( $t == "" ){
			return $t;
		}

		//-----------------------------------------
		// Remove <br>s 'cos we know they can't
		// be user inputted, 'cos they are still
		// &lt;br&gt; at this point :)
		//-----------------------------------------

		/*		if ( $this->pp_nl2br != 1 )
		{
		$t = str_replace( "<br>"    , "\n" , $t );
		$t = str_replace( "<br />"  , "\n" , $t );
		}*/

		$t = str_replace( "&#39;"   , "'", $t );
		$t = str_replace( "&#33;"   , "!", $t );
		$t = str_replace( "&#036;"  , "$", $t );
		$t = str_replace( "&#124;"  , "|", $t );
		$t = str_replace( "&amp;"   , "&", $t );
		$t = str_replace( "&gt;"    , ">", $t );
		$t = str_replace( "&lt;"    , "<", $t );
		$t = str_replace( "&quot;"  , '"', $t );

		//-----------------------------------------
		// Take a crack at parsing some of the nasties
		// NOTE: THIS IS NOT DESIGNED AS A FOOLPROOF METHOD
		// AND SHOULD NOT BE RELIED UPON!
		//-----------------------------------------

		$t = preg_replace( "/javascript/i" , "j&#097;v&#097;script", $t );
		$t = preg_replace( "/alert/i"      , "&#097;lert"          , $t );
		$t = preg_replace( "/about:/i"     , "&#097;bout:"         , $t );
		$t = preg_replace( "/onmouseover/i", "&#111;nmouseover"    , $t );
		$t = preg_replace( "/onmouseout/i", "&#111;nmouseout"    , $t );
		$t = preg_replace( "/onclick/i"    , "&#111;nclick"        , $t );
		$t = preg_replace( "/onload/i"     , "&#111;nload"         , $t );
		$t = preg_replace( "/onsubmit/i"   , "&#111;nsubmit"       , $t );
		//$t = preg_replace( "/object/i"   , "&#111;bject"       , $t );
		//$t = preg_replace( "/frame/i"   , "fr&#097;me"       , $t );
		$t = preg_replace( "/applet/i"   , "&#097;pplet"       , $t );
		$t = preg_replace( "/meta/i"   , "met&#097;"       , $t );
		//$t = preg_replace( "/embed/i"   , "met&#097;"       , $t );

		return $t;
	}
	static function word_limit($string, $length, $ellipsis="...") {
		return (count($words = explode(' ', $string)) > $length) ? implode(' ', array_slice($words, 0, $length)) . $ellipsis : $string;
	}

	static function make_single_space($t=""){
		return ($t=="") ? $t : preg_replace("#[[:space:]]+#", " ", $t);
	}

	static function CheckDir($pDir){
		if (is_dir($pDir))
		return true;
		if (!@mkdir($pDir,0777,true)){
			return false;
		}
		self::chmod_dir($pDir,0777);
		return true;
	}

	static function chmod_dir($dir,$mod=0777){
		$parent_dir=dirname(str_replace(ROOT_PATH,'',$dir));
		if($parent_dir!='' && $parent_dir!='.'){
			//echo $parent_dir.'/<br />';
			@chmod($dir,$mod);
			self::chmod_dir($parent_dir,$mod);
		}
		return true;
	}


	static function getOption($options_array,$selected){
		$input='';
		if ($options_array)
		foreach($options_array as $key=>$text){
			$input .= '<option value="'.$key.'"';
			if($key==='' && $selected==='')
			{
				$input .=  ' selected';
			}
			else
			if( $selected!=='' && $key==$selected )
			{
				$input .=  ' selected';
			}
			$input .= '>'.$text.'</option>';
		}
		return $input;
	}

	static function getOptionMulti($options,$select_array){
		if ($options)
		foreach($options as $key=>$text){
			$input .= '<option value="'.$key.'"';
			if(in_array($key,$select_array))
			{
				$input .=  ' selected';
			}

			$input .= '>'.$text.'</option>';
		}
		return $input;
	}

	static function getOptionNum($min,$max,$default=1){
		$options = '';
		for($i=$min;$i<=$max;$i++){
			$options .= '<option value="';
			if ( $i<10 )
			$options .= '0'.$i.'"';
			else
			$options .= $i.'"';
			if ( $i == $default )
			{
				$options .= ' selected';
			}
			$options .= '>'.$i.'</option>';
		}
		return $options;
	}

	static function getParamSearch($str_search){
		$str_search = str_replace( array('+','/','|','-','*') , "", $str_search );
		$str_search = self::trimSpace($str_search);
		$str_search = str_replace( "'" , '"', $str_search );
		$str_search = str_replace( "&#39;" , '"', $str_search );
		$str_search = str_replace( "&quot;" , '"', $str_search );

		if (eregi('"',$str_search) ){
			$pattern = '#\"(.+?)\"#is';
			preg_match_all($pattern, $str_search, $matches);
			$chars = preg_split($pattern, $str_search);

			$results .= implode(" ",$matches[0]);
			foreach ($chars as $row){
				if ($row){
					$row_array = explode(' ', $row);
					if (is_array($row_array)){
						foreach ($row_array as $word){
							if ($word) $results.=" +".trim($word)."";
						}
					}
					else{
						$results.=" +".trim($row)."";
					}
				}
			}
			return $results;
		}
		else{
			$search_array = explode(' ', $str_search);
			$content = implode(" +",$search_array);
			$content ="+".$content.'';
			return $content;
		}
	}

	static function trimSpace($str=""){
		if($str==""){
			return;
		}
		$str = str_replace("&nbsp;", " ", $str);
		$str = preg_replace('![\t ]*[\r\n]+[\t ]*!', ' ', $str);
		$str = trim($str);
		return $str;
	}

	static function delDoubleSpace($str){
		return preg_replace('/  {2,}/',' ',$str);
	}
					
	//TuấnNK add ( 2008/05/23 12h17 ) hàm đếm ký tự viết hoa
	static function countUpChars($str){
		if($str!=''){
			$strNotAllow = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z Á À Ã Ạ Â Ấ Ầ Ẫ Ậ Ă Ắ Ằ Ẵ Ặ É È Ẽ Ẹ Ê Ế Ề Ễ Ệ Í Ì Ĩ Ị Ó Ò Õ Ọ Ô Ố Ồ Ỗ Ộ Ơ Ớ Ờ Ỡ Ợ Ú Ù Ũ Ụ Ư Ứ Ừ Ữ Ự Ý Ỳ Ỹ Ỵ";
			$checkArray=(explode(' ',$strNotAllow));
			$intCount = 0;

			foreach ($checkArray as $checkChar) {
				$intCount+=substr_count($str,$checkChar);
			}
			return ($intCount<=floor(strlen($str)/3));
		}
		return true;
	}

	static function IsSearchE(){
		$lSearchEngineArray=array("Google","yahoo","Fast", "Slurp", "Ink", "Atomz", "Scooter", "Crawler", "MSNbot", "Poodle", "Genius");
		$SearchEngineList =  join('|',$lSearchEngineArray);
		if(preg_match("/($SearchEngineList)/is",$_SERVER['HTTP_USER_AGENT'])){
			return true; // search engine
		}
		return false; // user
	}


	static function reload_captcha()
	{
		$alphanum		= "abcdefghiklmopqrstuvwxyz0123456789";
		$new_string	= substr(str_shuffle($alphanum), 0, 3);
		$_SESSION["enbac_validate"] = $new_string;
	}

	//get real IP - by TuanNV - 26/09/08
	static function ip_first($ips) {
	  if (($pos = strpos($ips, ',')) != false) {
	    return substr($ips, 0, $pos);
	  } else {
	    return $ips;
	  }
	}

	static function ip_valid($ips) {
	  if (isset($ips)) {
	    $ip    = self::ip_first($ips);
	    $ipnum = ip2long($ip);
	    if ($ipnum !== -1 && $ipnum !== false && (long2ip($ipnum) === $ip)) { // PHP 4 and PHP 5
	      if (($ipnum < 167772160   || $ipnum >   184549375) && // Not in 10.0.0.0/8
	          ($ipnum < -1408237568 || $ipnum > -1407188993) && // Not in 172.16.0.0/12
	          ($ipnum < -1062731776 || $ipnum > -1062666241))   // Not in 192.168.0.0/16
	        return true;
	    }
	  }
	  return false;
	}

	static function ip() {
	  $check = array('HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED',
	                 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED',
	                 'HTTP_VIA', 'HTTP_X_COMING_FROM', 'HTTP_COMING_FROM');
	  foreach ($check as $c) {
	    //if (self::ip_valid(&$_SERVER[$c])) {
	    if (isset($_SERVER[$c]) && self::ip_valid($_SERVER[$c])) {
	      return self::ip_first($_SERVER[$c]);
	    }
	  }

	  return $_SERVER['REMOTE_ADDR'];
	}

	static function session_started(){
		return isset($_SESSION);
	}

	function limit_char_per_word($str="",$limit=10){
		if(!FunctionLib::countUpChars($str)){
			$str = FunctionLib::convertUnicodeCaseWithoutHtml($str);
		}

		$arr_tmp = explode(' ',$str);
		$str_tmp = '';
		foreach($arr_tmp as $ar){
			if(strlen($ar)>$limit){
				$str_tmp .= ' '.substr($ar,0,$limit);
			}
			else{
				$str_tmp .= ' '.$ar;
			}
		}

		return trim($str_tmp);
	}

	static function mouse_hover($color='#EAF1FB',$return=false){
		$str= ' onmouseover="shop.hover.over(this,\''.$color.'\')" onmouseout="shop.hover.out(this)" ';
		if($return)return $str;else echo $str;
	}


	static function word_length_sort($a, $b){
		if ( mb_strlen($a['contents'],'UTF-8') == mb_strlen($b['contents'],'UTF-8') ){
			return 0;
		}
		return ( mb_strlen($a['contents'],'UTF-8') > mb_strlen($b['contents'],'UTF-8') ) ? -1 : 1;
	}

	static function  check_uri(){
		if(!self::$check_uri){
			CGlobal::$request_uri = $_SERVER['REQUEST_URI'];
			if(isset($_SERVER['HTTP_REFERER'])){
				CGlobal::$referer_url = $_SERVER['HTTP_REFERER'];
			}

			CGlobal::$query_string=$_SERVER['QUERY_STRING']?'?'.$_SERVER['QUERY_STRING']:'';
			$dir=(dirname($_SERVER['SCRIPT_NAME'])?dirname($_SERVER['SCRIPT_NAME']):'');

			$dir = str_replace('\\','/',$dir);

			if($dir && $dir!='/' && $dir!='./'){
				if($dir[0]!='/'){
					$dir='/'.$dir;
				}
				$dir.=$dir[strlen($dir)-1]!='/'?'/':'';
				CGlobal::$query_string = str_replace($dir,'',CGlobal::$request_uri);
			}
			else{
				$uri=CGlobal::$request_uri;
				if(strlen($uri)>1){

					while($uri[0]=='/'){
						$uri=substr($uri,1,strlen($uri)-1);
					}

					CGlobal::$query_string = $uri;
					unset($uri);
				}
				else{
					CGlobal::$query_string = '';
				}
			}

			self::$check_uri = true;
		}
	}
	static function is_valid_email($email) {
	  $result = true;
	  $email = strtolower(trim($email));
	  if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/", $email)) {
	    $result = false;
	  }
	  return $result;
	}
	
	static function is_mobile($value = ''){
		return preg_match('#^(01([0-9]{2})|09[0-9])(\d{7})$#', $value);
	}

	static function empty_dir($name)
	{
		if($dir = @opendir($name)){
			while($file=readdir($dir)){
				if($file!='..'){
					@unlink($file);
				}
			}
			closedir($dir);
		}
	}

	static function empty_all_dir($name, $remove_sub_dir = false,$remove_self=false){
		if(is_dir($name)){
			if($dir = opendir($name)){
				$dirs = array();
				while($file=readdir($dir)){
					if($file!='..' and $file!='.'){
						if(is_dir($name.'/'.$file)){
							$dirs[]=$file;
						}
						else{
							@unlink($name.'/'.$file);
						}
					}
				}
				closedir($dir);
				foreach($dirs as $dir_){
					if($remove_self || $remove_sub_dir)
						self::empty_all_dir($name.'/'.$dir_, true,true);
					else
						self::empty_all_dir($name.'/'.$dir_, false,false);
				}

				if($remove_self){
					@rmdir($name);
				}
			}
		}
	}

	//for json
	static function JsonErr($msg = '', $mixed = array()){
		$arr = array('err' => -1, 'msg' => $msg);
		if(!empty($mixed)){
			$arr = $arr + $mixed;
		}
		return json_encode($arr);
	}
	static function JsonSuccess($msg, $mixed = array()){
		$arr = array('err' => 0, 'msg' => $msg);
		if(!empty($mixed)){
			$arr = $arr + $mixed;
		}
		return json_encode($arr);
	}
	static function numberFormat($number = 0){
		if($number >= 1000){
			return number_format($number,0,',','.');
		}
		return $number;
	}
	static function priceFormat($price = 0,$currency = ''){
		if($currency == ''){
			$currency = CGlobal::$currency;
		}
		return self::numberFormat($price)." $currency";
	}
	static function dateFormat($time = TIME_NOW, $format = 'd/m - H:i', $vietnam = false){
		$return = date($format,$time);
		if ($vietnam){
			$days = array('Mon' => 'Thứ 2', 'Tue' => 'Thứ 3', 'Wed' => 'Thứ 4', 'Thu' => 'Thứ 5', 'Fri' => 'Thứ 6', 'Sat' => 'Thứ 7', 'Sun' => 'Chủ nhật');
			$return = date('H:i - ',$time).$days[date('D',$time)].', ngày '.date('d/m/Y',$time);
		}
		return $return;
	}

	//for emotions
	static function parseEmoticon($text,$direct = false){
		if(trim($text) == '') return '';

		$emoticon_dir = ($direct?WEB_ROOT:'').'style/images/smiley/';
		$emoticon_dir = '<img border="0" src="'.$emoticon_dir;

		$arr_replace = array(
			'/;;\)/is'	=>	$emoticon_dir.'5.gif" />'
			,'/;\)\)/is'=>	$emoticon_dir.'6.gif" />'
			,'/>:D</is'	=>	$emoticon_dir.'61.gif" />'
			,'/:-\//is'	=>	$emoticon_dir.'7.gif" alt=":-/" title=":-/" />'

			,'/:-\*/is'	=>	$emoticon_dir.'11.gif" alt=":-*" title=":-*" />'
			,'/=\(\(/is'=>	$emoticon_dir.'12.gif" alt="=((" title="=((" />'
			,'/:-O/is'	=>	$emoticon_dir.'13.gif" alt=":-O" title=":-O" />'

			,'/:>/is'	=>	$emoticon_dir.'15.gif" alt=":>" title=":>" />'
			,'/B-\)/is'	=>	$emoticon_dir.'16.gif" />'

			,'/#:-S/is'	=>	$emoticon_dir.'18.gif" />'
			,'/:-SS/is'	=>	$emoticon_dir.'42.gif" />'
			,'/:-S/is'	=>	$emoticon_dir.'17.gif" alt=":-S" title=":-S" />'

			,'/>:\)/is'	=>	$emoticon_dir.'19.gif" />'
			,'/:\(\(/is'=>	$emoticon_dir.'20.gif" />'
			,'/:\)\)/is'=>	$emoticon_dir.'21.gif" />'

			,'/\/:\)/is'=>	$emoticon_dir.'23.gif" />'
			,'/=\)\)/is'=>	$emoticon_dir.'24.gif" alt="=))" title="=))" />'
			,'/O:-\)/is'=>	$emoticon_dir.'25.gif" alt="O:-)" title="O:-)" />'

			,'/=;/is'	=>	$emoticon_dir.'27.gif" alt="=;" title="=;" />'
			,'/I-\)/is'	=>	$emoticon_dir.'28.gif" alt="I-)" title="I-)" />'
			,'/8-\|/is'	=>	$emoticon_dir.'29.gif" alt="8-|" title="8-|" />'
			,'/L-\)/is'	=>	$emoticon_dir.'30.gif" alt="L-)" title="L-)" />'
			,'/:-&/is'	=>	$emoticon_dir.'31.gif" alt=":-&" title=":-&" />'
			,'/:-\$/is'	=>	$emoticon_dir.'32.gif" alt=":-$" title=":-$" />'
			,'/\[-\(/is'=>	$emoticon_dir.'33.gif" alt="[-(" title="[-(" />'
			,'/:O\)/is'	=>	$emoticon_dir.'34.gif" alt=":O)" title=":O)" />'
			,'/8-\}/is'	=>	$emoticon_dir.'35.gif" alt="8-}" title="8-}" />'
			,'/<:-P/is'	=>	$emoticon_dir.'36.gif" />'
			,'/\(:\|/is'=>	$emoticon_dir.'37.gif" />'
			,'/=P\~/is'	=>	$emoticon_dir.'38.gif" alt="=P~" title="=P~" />'
			,'/:-\?/is'	=>	$emoticon_dir.'39.gif" alt=":-?" title=":-?" />'
			,'/#-o/is'	=>	$emoticon_dir.'40.gif" alt="#-o" title="#-o" />'
			,'/=D>/is'	=>	$emoticon_dir.'41.gif" alt="=D>" title="=D>" />'

			,'/@-\)/is'	=>	$emoticon_dir.'43.gif" alt="@-)" title="@-)" />'
			,'/:\^o/is'	=>	$emoticon_dir.'44.gif" alt=":^o" title=":^o" />'
			,'/:-w/is'	=>	$emoticon_dir.'45.gif" alt=":-w" title=":-w" />'
			,'/:-</is'	=>	$emoticon_dir.'46.gif" alt=":-<" title=":-<" />'
			,'/>:P/is'	=>	$emoticon_dir.'47.gif" />'
			,'/<\):\)/is'	=>	$emoticon_dir.'48.gif" />'
			,'/\^#\(\^/is'	=>	$emoticon_dir.'49.gif" alt="^#(^" title="^#(^" />'
			,'/:\)\]/is'	=>	$emoticon_dir.'50.gif" />'
			,'/:-c/is'	=>	$emoticon_dir.'51.gif" alt=":-c" title=":-c" />'
			,'/\~X\(/is'=>	$emoticon_dir.'52.gif" />'
			,'/:-h/is'	=>	$emoticon_dir.'53.gif" alt=":-h" title=":-h" />'
			,'/:-t/is'	=>	$emoticon_dir.'54.gif" alt=":-t" title=":-t" />'
			,'/8->/is'	=>	$emoticon_dir.'55.gif" alt="8->" title="8->" />'
			,'/X_X/is'	=>	$emoticon_dir.'56.gif" alt="X_X" title="X_X" />'
			,'/:!!/is'	=>	$emoticon_dir.'57.gif" alt=":!!" title=":!!" />'
			,'/\\\m\//is'	=>	$emoticon_dir.'58.gif" alt="\m/" title="\m/" />'
			,'/:-q/is'	=>	$emoticon_dir.'59.gif" alt=":-q" title=":-q" />'
			,'/:-bd/is'	=>	$emoticon_dir.'60.gif" />'
			,'/:x/is'	=>	$emoticon_dir.'8.gif" alt=":x" title=":x" />'
			,'/:">/is'	=>	$emoticon_dir.'9.gif" alt=":&quot;>" title=":&quot;>" />'

			,'/X\(/is'	=>	$emoticon_dir.'14.gif" alt="X(" title="X(" />'
			,'/:-B/is'	=>	$emoticon_dir.'26.gif" alt=":-B" title=":-B" />'
			,'/:\)/is'	=>	$emoticon_dir.'1.gif" alt=":)" title=":)" />'
			,'/:\(/is'	=>	$emoticon_dir.'2.gif" alt=":(" title=":(" />'
			,'/;\)/is'	=>	$emoticon_dir.'3.gif" alt=";)" title=";)" />'
			,'/:D/is'	=>	$emoticon_dir.'4.gif" alt=":D" title=":D" />'
			,'/:\|/is'	=>	$emoticon_dir.'22.gif" alt=":|" title=":|" />'
			,'/:P/is'	=>	$emoticon_dir.'10.gif" alt=":P" title=":P" />'
		);

		$text_replace = array();
		foreach (array_keys($arr_replace) as $value){
			$text_replace[] = htmlspecialchars($value);
		}
		$text = preg_replace($text_replace,$arr_replace,$text);

		return $text;
	}

	//duration time
	static function duration_time($time){
		$time = TIME_NOW - $time;

		if($time>0){
			if($time>(365*86400)){
				return floor($time/(365*86400)).' năm trước';
			}

			if($time>(30*86400)){
				return floor($time/(30*86400)).' tháng trước';
			}

			if($time>(7*86400)){
				return floor($time/(7*86400)).' tuần trước';
			}
			if($time>86400){
				return floor($time/(86400)).' ngày trước';
			}

			if($time>3600){
				return floor($time/(3600)).' giờ trước';
			}

			if($time>60){
				return floor($time/(60)).' phút trước';
			}
		}
		return ' vài giây trước';
	}

	//clean & valid url
	static function convertURL($link = ''){
		$http = (preg_match_all("#^(http\:\/\/)#", $link) > 0) ? '' : 'http://';
		return $http.$link;
	}

	//hidden uid
	static function hiddenID($id = 0, $decode = false){
		if($decode){
			$id = (1984 - 13*12) + $id;
		}else{
			$id = (13*12 - 1984) + $id;
		}
		return $id;
	}
	
	//send sms to customer
	static function sendAtmSMS($customerInfo = array()){
		if($customerInfo['cod_type'] == 0 && $customerInfo['payment_type'] == 0 && $customerInfo['cash_transfer'] == 0){
			$bank = FunctionLib::detectBank($customerInfo['admin_note']);
			$bank = FunctionLib::getAtmBankSms($bank);
			include_once(ROOT_PATH.'core/sendSMS.php');
			$sms = new sendSMS();
			$textSMS =
"Quy khach TT ".($customerInfo['total_price']*$customerInfo['quantity'])."d ve:
So TK: ".$bank['code']."
NH ".$bank['name']."
Chu TK: Cty CP Truyen thong VN
Ly do: Muachung.vn ".$customerInfo['order_code'];
			$return = $sms->send($customerInfo['phone'],$textSMS);
			if($return == 'success'){
				return true;
			}
		}
		return false;
	}
	
	static function runSendMailWhenClose($order_info = array()){
		global $successOrderMail;
		if(!empty($successOrderMail)){
			$order_info = $successOrderMail['info'];
			//gui mail thanh cong
			if(EmailLib::sendEmailAfterBuy($order_info)){
				$order_info['log'] = MuaChungLog::orderLog($order_info['id'], array('checkout-email'), $successOrderMail, false, 'sys');
				DB::update(T_ORDERS, array('log' => $order_info['log']), 'id='.$order_info['id']);
			}
			//gui sms atm
			if(SEND_SMS_AFTER_PAYMENT_ATM == 1){
				if(FunctionLib::sendAtmSMS($order_info)){
					$order_info['log'] = MuaChungLog::orderLog($order_info['id'], array('atm-sms'), $successOrderMail, false, 'sys');
					DB::update(T_ORDERS, array('log' => $order_info['log']), 'id='.$order_info['id']);
				}
			}
			
			if(orderLib::isOnline($order_info) || orderLib::isGold($order_info)){
				require_once ROOT_PATH.'core/Coupon.php';
				Coupon::sendCouponAfterBuy($order_info);
			}
		}
	}
	
	static function isUrlString($str = ''){
		return (bool)preg_match("#^[a-zA-Z][0-9-_a-zA-Z]*$#", $str);
	}
	
	static function getMenu($type = 1){
		$type = ($type == 2 || $type == 3) ? $type : 1;
		$arr  = array();
		foreach(CGlobal::$menu as $k => $v){
			if($v['position'] == $type){
				$arr[$k] = $v;
			}
		}
		return $arr;
	}
	static function datetimeToTimestamp($datetime=''){
        if (!$datetime || $datetime=='0000-00-00 00:00:00') return time();
    
        list($date, $time) = explode(' ', $datetime);
        list($year, $month, $day) = explode('-', $date);
        list($hour, $minute, $second) = explode(':', $time); 
        return mktime($hour, $minute, $second, $month, $day, $year);
    }
	
	static function orderCode($province = 0, $id = 0){
		//$province = ($province == 22) ? '04' : ($province == 29 ? '08' : '01');
		//return "$province-$id-".TIME_NOW;
		return "$id-".TIME_NOW;
	}
	
	static function orderError($id = 0, $error_code = ''){
		$_SESSION[MEMCACHE_ID.'cart-step'] = 5;
        Url::redirect('payment', array('step' => 'error', 'id' => $id, 'error' => $error_code));
	}
	
	static function getAtmBank($bank = ''){
        $html = array('owner' => 'Công ty Cổ phần Truyền thông Việt Nam');
		$arrTemp = array(
			'vc_bank' => array(
				'code' 	=> '002.1.00.183924.3',
				'name' 	=> 'Ngân hàng Vietcombank (VCB) Hà Nội',
				'id' 	=> 'vcb',
				'logo' 	=> 'vietcom-bank.gif'
			),
			'donga_bank' => array(
				'code' => '002387340001',
				'name' => 'Ngân hàng Đông Á chi nhánh Bạch Mai - Hà Nội',
				'id' => 'donga',
				'logo' => 'donga-bank.gif'
			),
			'techcom_bank' => array(
				'code' => '10320141354011',
				'name' => 'Ngân hàng Techcombank CN Thăng Long',
				'id' => 'techcom',
				'logo' => 'techcombank.gif'
			),
			'agribank' => array(
				'code' => '1483.2010.047.40',
				'name' => 'Ngân hàng AGRIBANK chi nhánh Thủ Đô',
				'id' => 'agri',
				'logo' => 'agribank.gif'
			),
			'agri_bank'	=> array(
				'code' => '1483.2010.047.40',
				'name' => 'Ngân hàng AGRIBANK chi nhánh Thủ Đô',
				'id' => 'agri',
				'logo' => 'agribank.gif'
			),
		   'bidv_bank' => array(
				'code' => '12010000318895',
				'name' => 'Ngân hàng BIDV Sở Giao dịch',
				'id' => 'bidv',
				'logo' => 'bidv.gif'
			),
		   'vietin_bank' => array(
				'code' => '1020.1000.1108.169',
				'name' => 'Ngân hàng Công thương Việt Nam chi nhánh Hai Bà Trưng',
				'id' => 'vietin',
				'logo' => 'vietinbank.gif'
			),
		   'vietinbank' => array(
				'code' => '1020.1000.1108.169',
				'name' => 'Ngân hàng Công thương Việt Nam chi nhánh Hai Bà Trưng',
				'id' => 'vietin',
				'logo' => 'vietinbank.gif'
			),
			'mb_bank' => array(
				'code' => '0651100016002',
				'name' => 'Ngân hàng thương mại cổ phần Quân đội - CN Hai Bà Trưng (MB)',
				'id' => 'mb',
				'logo' => 'mb.png'
			),
		   'acb_bank' => array(
				'code' => '37182319',
				'name' => 'Ngân hàng Á Châu chi nhánh Hà Nội (ACB)',
				'id' => 'acb',
				'logo' => 'acb.png'
			),
		   'vib_bank' => array(
				'code' => '001704060035755',
				'name' => 'Ngân hàng TMCP Quốc tế Việt Nam (VIB)',
				'id' => 'vib',
				'logo' => 'vib-bank.gif'
			)
		);
		if($bank){
			$html = ($bank == 'all') ? $arrTemp : $arrTemp[$bank];
		}
        return $html;
    }
	
	function getAtmBankSms($bank = ''){
        $html = array('owner' => 'Cty CP truyen thong Viet Nam');
		$arrTemp = array(
			'vc_bank' => array('code' => '0021001839243', 'name' => 'VCB Ha Noi'),
			'donga_bank' => array('code' => '002387340001', 'name' => 'Dong A CN Bach Mai HN'),
			'techcom_bank' => array('code' => '10320141354011', 'name' => 'Techcombank CN Thang Long'),
			'agribank' => array('code' => '1483201004740', 'name' => 'Agribank CN Thu Do'),
			'agri_bank'	=> array('code' => '1483201004740', 'name' => 'Agribank CN Thu Do'),
			'bidv_bank'	=> array('code' => '12010000318895', 'name' => 'BIDV So Giao dich'),
			'vietin_bank' => array('code' => '102010001108169', 'name' => 'Vietinbank CN Hai Ba Trung HN'),
			'vietinbank' => array('code' => '102010001108169', 'name' => 'Vietinbank CN Hai Ba Trung HN'),
			'mb_bank' => array('code' => '0651100016002', 'name' => 'MB - CN Hai Ba Trung'),
			'acb_bank' => array('code' => '37182319', 'name' => 'ACB - CN Ha Noi'),
			'vib_bank' => array('code' => '001704060035755','name' => 'VIB')
		);
		if($bank){
			$html = ($bank == 'all') ? $arrTemp : $arrTemp[$bank];
		}
        return $html;
    }
	function detectBank($txt = ''){
        if($txt){
            $txt = strip_tags($txt);
			if(stripos($txt,'tận nơi') !== false){
                return 'home';
            }else if(stripos($txt,'Vietcombank') !== false){
                return 'vc_bank';
            }else if(stripos($txt,'Techcombank') !== false){
                return 'techcom_bank';
            }else if(stripos($txt,'BIDV') !== false){
                return 'bidv_bank';
            }else if(stripos($txt,'AGRIBANK') !== false){
                return 'agribank';
			}else if(stripos($txt,'Á Châu')!==false){
                return 'acb_bank';
            }else if(stripos($txt,'Công thương Việt Nam') !== false){
                return 'vietinbank';
			}else if(stripos($txt,'Quân đội') !== false){
                return 'mb_bank';
            }else if(stripos($txt,'Đông Á') !== false){
                return 'donga_bank';
            }else if(stripos($txt,'VIB') !== false){
                return 'vib_bank';
            }
            return 'vccorp';
        }
        return '';
    }
	static function detectCity(){
		$city = FunctionLib::get_cookie('city',0);
		if(isset($_GET['province']) && $_GET['province'] != ''){
			$city = strtolower(trim($_GET['province']));
			foreach(CGlobal::$province as  $p){
				if($p['status'] == '1' && $p['safe_name'] == $city){
					$city = $p['id'];
					break;
				}
			}
		}
		return $city;
	}
	static function insertReferIp($refer = 0){
		if($refer > 0){
			if(!goldLib::checkReferIp(0,$refer,true,2)){
				FunctionLib::my_setcookie('referId',$refer,TIME_NOW+86400*3);
				return true;
			}
		}
		return false;
	}
	static function insertDBReferIp($order_id,$quantity = 1){
		$refer = FunctionLib::get_cookie('referId',0);
		if($refer > 0 && !goldLib::checkReferIp(0,$refer,true,2)){
			DB::insert(T_REFER,array('ip'=>FunctionLib::ip(),'order_id'=>$order_id,'order_quantity'=>$quantity,'order_remain'=>$quantity,'customer_id'=>$refer,'created'=>TIME_NOW));
			return true;
		}
		return false;
	}
	static function getBodyBG(){
		$page = Url::get('page');
		if($page != 'edit_page' && $page != 'admin' && $page != 'page' && $page != 'module'){
			$bg = '';
			if($page == 'product' || $page == 'comment' || $page == 'refer'){
				$id = FunctionLib::getParamInt('id',0);
				if($id > 0){
					$item = Item::get_item($id, true);
					if(isset($item['background']) && $item['background'] != ''){
						$bg = ImageUrl::getProductBG($item['background']);
					}else{
						$bg = CGlobal::$background;
					}
				}
			}else{
				$bg = CGlobal::$background;
			}
			if($bg != ''){
				if($bg == CGlobal::$background){
					echo ' style="background:#BCC7C9 url('.$bg.') repeat-x"';
				}else{
					echo ' style="background-image:url('.$bg.')"';
				}
			}
		}
	}
	static function createShareLink($type = 'fb',$link = '',$title = ''){
		$url = '';
		if($link != ''){
			$enLink = urlencode($link);
			$title = ($title != '') ? urlencode($title) : 'Muachung.vn';
			if($type == 'fb'){
				$url = FACEBOOK_URL.'/share.php?u='.$enLink.'&t='.$title;
			}
			if($type == 'tw'){
				$url = 'http://twitter.com/share?url='.$enLink.'&text='.$title;
			}
			
		}
		return $url;
	}
	//order view code
	static function createOrderViewCode(){
		$code = md5(TIME_NOW.' - abc@123456789pam');
		$_SESSION[MEMCACHE_ID.'view_order_me'] = $code;
		return $code;
	}
	static function checkOrderViewCode($code = ''){
		return isset($_SESSION[MEMCACHE_ID.'view_order_me']) && $_SESSION[MEMCACHE_ID.'view_order_me'] == $code;
	}
	static function convertOnlyNumber($string){
		$string = preg_replace('/[^0-9]/', '', $string);
		return $string;
	}
	
	static function isMuachungHost(){
		$arrServer = array('muachung.vn',
						   'localhost',
							'dev.muachung.vn',
							'192.168.28.71',
							'192.168.28.43'
							);
		return in_array($_SERVER["HTTP_HOST"], $arrServer);
	}
	
	static function redirectGalaxy($url = '', $item = array(), $type = 301){
		if($url != '' && isset($item['is_loto'])){
			$new_url = '';
			if(FunctionLib::isMuachungHost()){
				if($item['is_loto'] == 1){
					$new_url = str_replace($_SERVER["HTTP_HOST"], 'galaxys.muachung.vn', $url);
				}
			}else{
				if($item['is_loto'] == 0){
					$new_url = str_replace($_SERVER["HTTP_HOST"], 'muachung.vn', $url);
				}
			}
			if($new_url != '' && $new_url != $url){
				if($type == 301){
					Header( "HTTP/1.1 301 Moved Permanently" );
				}
				Header('Location:'.$new_url);
			}
		}
	}
	static function remove_4_js($t) {
        $t = str_replace("&#39;", "", $t);
        $t = str_replace("!", "&#33;", $t);
        $t = str_replace("$", "&#036;", $t);
        $t = str_replace("|", "&#124;", $t);
        $t = str_replace(">", "&gt;", $t);
        $t = str_replace("<", "&lt;", $t);
        $t = str_replace('"', "&quot;", $t);
        $t = str_replace( '&quot;', "" , $t );

        return trim($t);
    }
    static function addCondition($condition = array()){
    	if(!empty($condition)){
    		$numCondition = count($condition);
    		$newCondition = array();
    		foreach ($condition as $k=>$c){
    			if(strpos($c,' = ') > 0){
    				$newCondition[$k] = $c;
    			}
    			else{
    				$newCondition[$numCondition] = $c;
    				$numCondition ++;
    			}
    		}
    		sort($newCondition);
    		return implode(' AND ', $newCondition);
    	}
    	return '';
    }
	static function sendMailToCustomer($customerInfo = array(), $atm = ''){
		$customerInfo['atm'] = $atm;
		return EmailLib::sendEmailAfterBuy($customerInfo);
	}
	static function facebookMetaData(){
		if(CGlobal::$current_page == 'product'){
			$id = FunctionLib::getParamInt('id', 0);
			$item = Item::getItem($id, 209, 86400);
			if($item){
				return
'<meta property="og:title" content="'.addslashes(htmlspecialchars($item['title'])).'" />
<meta property="og:type" content="product" />
<meta property="og:url" content="'.($item['link']."?utm_source=FBapp&utm_medium=linkviral&utm_campaign=Loantin").'" />
<meta property="og:image" content="'.$item['image'].'" />
<meta property="og:site_name" content="MuaChung" />
<meta property="fb:app_id" content="'.(CGlobal::$oAuth['facebook']['app_id']).'" />
<meta property="og:description" content="'.FunctionLib::descriptionText($item['sort_description']).'" />
<link rel="image_src" href="'.$item['image'].'" />';
			}
		}
	}
}
?>